package com.eos.orm.mybatis.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.eos.orm.mybatis.dao.ProductBrandMapper;
import com.eos.orm.mybatis.model.ProductBrand;
import com.eos.orm.mybatis.model.ProductBrandExample;

/**
 * product_brand产品品牌表的CURD操作
 * 
 * @author sz
 * 
 */
public class ProductBrandMapperImpl extends AbstractSqlSessionFactory implements
		ProductBrandMapper {

	public int countByExample(ProductBrandExample example) {
		return 0;
	}

	public int deleteByExample(ProductBrandExample example) {
		return 0;
	}

	/**
	 * @param id
	 *            产品品牌的主键
	 * @return 成功0 失败-1
	 */
	public int deleteByPrimaryKey(Integer id) {
		SqlSession session = sqlSessionFactory.openSession();
		try {
			ProductBrandMapper mapper = session
					.getMapper(ProductBrandMapper.class);
			mapper.deleteByPrimaryKey(id);
			session.commit();
			mapper = null;
		} catch (Exception e) {
			System.out
					.println("com.eos.orm.mybatis.dao.impl.ProductBrandMapperImp.deleteByPrimaryKey throws exception:"
							+ e.getMessage());
			return -1;
		} finally {
			session.close();
		}
		return 0;
	}

	/**
	 * @param ProductBrand
	 *            产品品牌对象
	 * @return 成功0 失败-1
	 */
	public int insert(ProductBrand record) {
		SqlSession session = sqlSessionFactory.openSession();
		try {
			ProductBrandMapper mapper = session
					.getMapper(ProductBrandMapper.class);
			mapper.insert(record);
			session.commit();
			mapper = null;
		} catch (Exception e) {
			System.out
					.println("com.eos.orm.mybatis.dao.impl.ProductBrandMapperImp.insert throws exception:"
							+ e.getMessage());
			return -1;
		} finally {
			session.close();
		}
		return 0;
	}

	public int insertSelective(ProductBrand record) {
		return 0;
	}

	/**
	 * @param ProductBrandExample
	 *            带有查询条件的查询对象
	 * @return List<ProductBrand>
	 */
	public List<ProductBrand> selectByExample(ProductBrandExample example) {
		List<ProductBrand> templist = new ArrayList<ProductBrand>();
		SqlSession session = sqlSessionFactory.openSession();
		try {
			ProductBrandMapper mapper = session
					.getMapper(ProductBrandMapper.class);
			templist = mapper.selectByExample(example);
			mapper = null;
		} catch (Exception e) {
			System.out
					.println("com.eos.orm.mybatis.dao.impl.ProductBrandMapperImp.selectByExample throws exception:"
							+ e.getMessage());
		} finally {
			session.close();
		}
		return templist;
	}

	/**
	 * @param id
	 *            产品品牌的主键
	 * @return ProductBrand 通过主键ID查询产品品牌的对象
	 */
	public ProductBrand selectByPrimaryKey(Integer id) {
		SqlSession session = sqlSessionFactory.openSession();
		try {
			ProductBrandMapper mapper = session
					.getMapper(ProductBrandMapper.class);
			return mapper.selectByPrimaryKey(id);
		} catch (Exception e) {
			System.out
					.println("com.eos.orm.mybatis.dao.impl.ProductBrandMapperImp.selectByPrimaryKey throws exception:"
							+ e.getMessage());
		} finally {
			session.close();
		}
		return null;
	}

	public int updateByExample(ProductBrand record, ProductBrandExample example) {
		return 0;
	}

	public int updateByExampleSelective(ProductBrand record,
			ProductBrandExample example) {
		return 0;
	}

	public int updateByPrimaryKey(ProductBrand record) {
		return 0;
	}

	/**
	 * @param ProductBrand 通过主键ID更新ProductBrand所有的属性
	 * @return 成功0 失败-1
	 */
	public int updateByPrimaryKeySelective(ProductBrand record) {
		SqlSession session = sqlSessionFactory.openSession();
		try {
			ProductBrandMapper mapper = session
					.getMapper(ProductBrandMapper.class);
			mapper.updateByPrimaryKeySelective(record);
			session.commit();
			mapper = null;
		} catch (Exception e) {
			System.out
					.println("com.eos.orm.mybatis.dao.impl.ProductBrandMapperImp.updateByPrimaryKeySelective throws exception:"
							+ e.getMessage());
			return -1;
		} finally {
			session.close();
		}
		return 0;
	}

}
